#ifndef Event_Manager_h
#define Event_Manager_h

#include <set>
#include <map>
#include <vector>

namespace serika
{
	namespace ut
	{
		class Event;
		class EventHandler;

		class EventManager
		{
		public:
			EventManager();
			~EventManager();

		public:
			void RegistryEventType(int eventType);
			void AttachEventHandler(int eventType, EventHandler* handler);
			void DetachEventHandler(int eventType, EventHandler* handler);
			void DetachEventHandler(EventHandler* handler);

			void SendEvent(Event* e);
			void PostEvent(Event* e);

			void Dispatch();

		private:
			typedef std::set<EventHandler*> HandlerList;
			typedef std::map<int, HandlerList> HandlerMap; // map<EventType, List>
			HandlerMap mHandlerMap;

			typedef std::vector<Event*> EventList;
			EventList mEventList1;
			EventList mEventList2;
			EventList* mFrontList;
			EventList* mBackList;

		private:
			void RegistryPresetEventType();
			void DispatchEvent(Event* e);
			HandlerList& GetHandlerList(int eventType);

			void ClearEventList(EventList& eventList);
			void FlipEventList();
		};
	}
}

#endif
